import os
import numpy as np
import sys

from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge
from OCC.Core.gp import gp_Pnt
from OCC.Display.SimpleGui import init_display
from PyQt5.QtCore import pyqtSignal,pyqtSlot,QThread
from PyQt5.QtWidgets import QMainWindow,QApplication,QInputDialog,QFileDialog,\
    QMessageBox,QColorDialog,QListWidgetItem,QTableWidgetItem,QProgressBar,\
    QRadioButton,QMdiSubWindow,QWidget,QMenu
from PyQt5.QtCore import QPoint
from OCC.Extend.DataExchange import read_iges_file,read_step_file,\
    read_stl_file,write_iges_file,write_step_file,write_stl_file
import meshio
import gmsh
from hems import *
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
import matplotlib.pyplot as plt
from qtDisplay import qtViewer3d
from PyQt5.uic import loadUi
class Form(QWidget):

    def __init__(self):
        super(Form, self).__init__()
        loadUi('drawing.ui', self)

#二维直线生成
    def create_segment(pnt_list,close=True):
        if len(pnt_list)==1:
            return None
       #如果close为True，图形就会封闭
       #通过点集生成Edge，再将Edge添加到wire中
        wire = BRepBuilderAPI_MakeWire()
        for i in range(0,len(pnt_list)):
            if i==len(pnt_list)-1 and close:
                segment=BRepBuilderAPI_MakeEdge(pnt_list[0], pnt_list[len(pnt_list)-1])
            elif i!=len(pnt_list)-1:
                segment=BRepBuilderAPI_MakeEdge(pnt_list[i],pnt_list[i+1])
            else:
                continue
            wire.Add(segment.Edge())
        return wire
    shape = create_segment([gp_Pnt(0,0,0),gp_Pnt(0,1,0),gp_Pnt(1,1,0),gp_Pnt(1,0,0)])

    @pyqtSlot()
    def on_actionshow_clicked(self):
        display,start_display,add_menu,add_function_to_menu = init_display()
        display.DisplayShape(shape.Wire(), update=True)
        start_display()


